package analyser.node.v2;

import analyser.node.AbstractNodeAnalyser;
import kit.LetterIndexer;
import model.v2.smi.MibObjectIdentityNodeV2;
import util.common.CharType;
import util.common.MibKeys;

import java.util.List;

public class MibObjectIdentityV2Analyser extends AbstractNodeAnalyser<MibObjectIdentityNodeV2> {
    private MibObjectIdentityNodeV2 node2;

    public MibObjectIdentityV2Analyser(List<String> txtList) {
        super(txtList);
        node2 = node = new MibObjectIdentityNodeV2();
    }

    @Override
    protected void doAnalyse() {
        int state = 1;
        String str = null;
        while (state != 99){
            switch (state){
                case 1: //节点名
                    str = indexer.getNextIgnoreLeftSpace(CharType.Letter, CharType.Number, CharType.Hyphen);
                    if ((state = kit.notNull(str, 2, -state)) == 2){
                        node2.name = str;
                    }
                    break;
                case 2: //
                    state = kit.nextMatch(MibKeys.OBJECT_IDENTITY, 3, -state);
                    break;
                case 3: // STATUS
                    state = matchEssentialKeyValue(MibKeys.STATUS, false, CharType.Letter) ? 4 : -3;
                    break;
                case 4: // DESCRIPTION
                    state = matchEssentialKeyValue(MibKeys.DESCRIPTION, true) ? 5 : -4;
                    break;
                case 5: // REFERENCE
                    state = matchKeyValue(MibKeys.REFERENCE, false, true) ? 6 : -5;
                    break;
                case 6: // ::=
                    if ((state = kit.nextMatch(MibKeys.ASSIGNMENT, 99, -10)) == 99){
                        this.analyseLeaf();
                    }
                    break;
                default:
                    kit.ThrowAnalysisException("节点ObjectIdentity解析失败。", state, str);
            }
        }
        return;
    }
}
